<template>
    <div class="modal fade" id="WxMsgSetDetail" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true" witdh>
        <div class="modal-dialog">
            <div class="modal-content" style="width: 800px">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" @click="checkResult"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
                    <h4 class="modal-title" id="myModalLabel">设置推送节点</h4>
                </div>
                <div class="modal-body">
                    <div class="table-responsive">
                        <div style="text-align: right;margin: 0px 0px 10px 0px;"><Button class="btn-border" @click="changeAll(0)">全部关闭</Button> &nbsp;&nbsp;&nbsp; <Button  type="primary" @click="changeAll(1)">全部开启</Button></div>
                        <table class="table table-striped table-bordered min-width-790" >
                            <thead>
                            <tr>
                                <th width="60%">已支持的微信推送节点</th>
                                <th width="40%">是否启用该推送</th>
                            </tr>
                            </thead>
                            <tbody>
                            <tr v-for="(row, index) in wexinNodes">
                                <td class="node-title">{{row.modelTitle}}</td>
                                <td>
                                    <i-switch   @on-change="function(e){change(e,row)}"  :value="row.enabled == 1" >
                                        <span slot="open">开启</span>
                                        <span slot="close">关闭</span>
                                    </i-switch>
                                </td>
                            </tr>
                            </tbody>
                        </table>
                    </div>
                </div>
                <div class="modal-footer">
                    <Button type="primary" @click="saveWxMsg">保存设置</Button>
                </div>
            </div>
        </div>
    </div>
</template>

<script>
    export default {
        //接收父组件的绑定值
        props: ["caseMemberInfo"],
        data(){
            return{
                disabled:false,
                wexinNodes:[]
            }
        },
        mounted:function(){

        },
        methods:{
            initWeixinModelList: function() {
                var _self = this;
                var url = this.utilHelper.apiUrl + "/api/getWeiXinModelList";
                var body = {};
                body.params={};
                _self.$http.post(url, body).then((response) => {
                    var resData = response.body.resData;
                    if(resData.result == 1){
                       _self.wexinNodes = resData.list;
                    }else{
                        layer.msg("获取微信模板消息失败");
                    }
                });
            },
            change:function(status,wxMsgDetail){
                // this.disabled = true;
                //处理数据
                wxMsgDetail.enabled = status? 1:0;
                console.log(wxMsgDetail);
            },
            toSaveWxMsg(){
                
            },
            saveWxMsg(){
                //获取list reuseSmsSetting
                var _self = this;
                var changeList = []
                for(var i=0;i<_self.wexinNodes.length;i++){
                    changeList.push({wxModelmsgId:_self.wexinNodes[i].wxModelmsgId,enabled:_self.wexinNodes[i].enabled,companyId:_self.wexinNodes[i].companyId,wxModelType:_self.wexinNodes[i].wxModelType}   );
                }
                var body = {};
                body.params={changeList:changeList};
                var url = this.utilHelper.apiUrl + "/api/changeWeixinModelSetting";
                _self.$http.post(url, body).then((response) => {
                    var resData = response.body;
                    if(resData.result == 1){
                        layer.msg("设置成功");
                        $("#WxMsgSetDetail").modal("hide");
                        _self.$emit('checkWxPush');
                    }else{
                        layer.msg("设置微信模板消息失败");
                    }
                });
                console.log(this.wexinNodes)
            },
            changeAll(toValue){
                for(var i in this.wexinNodes){
                    this.wexinNodes[i].enabled= toValue
                }
            },
            checkResult(){
                var _self = this;
                $("#WxMsgSetDetail").modal("hide");
                _self.$emit('checkWxPush');
            }
        }
    }
</script>

<style scoped>
.node-title{text-align: left;}
</style>